<template>
  <div class="login-content">
    <div class="footer">
      <img src="../../assets/images/footer_bg.png" alt />
      <p>Copyright © www.AxureUX.com, All Rights Reserved.</p>
      <p>助你快速打造友好美观的交互原型</p>
    </div>
    <div class="login-ban clearfix">
      <img src="../../assets/images/login_ban.png" alt />
      <div class="login-icon">
        <el-image style="width: 120px; height: 120px" src :fit="'fit'">
          <div slot="error" class="image-slot"></div>
        </el-image>
      </div>
      <div class="text">
        <p>吉安12345后台管理平台</p>
        <!-- <p>Knowledge Base System</p> -->
      </div>
      <div class="loginform">
        <el-input
          placeholder="请输入用户名"
          v-model="ruleForm.username"
          class="mine-loginput"
          @focus="loginTip = ''"
          clearable
        >
          <i slot="prefix" class="fa fa-user-circle"></i>
        </el-input>
        <el-input
          placeholder="请输入密码"
          v-model="ruleForm.pass"
          class="mine-loginput pass"
          @focus="loginTip = ''"
          show-password
          clearable
        >
          <i slot="prefix" class="fa fa-lock"></i>
        </el-input>
        <el-button
          type="primary"
          class="mine-submit"
          :class="btnjump"
          @click="loginsubmit"
          :disabled="flagdisabled"
          >登录</el-button
        >
        <div class="login-tip">
          <el-alert
            :title="loginTip"
            type="info"
            v-if="loginTip != ''"
            :closable="false"
            show-icon
          ></el-alert>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import md5 from "js-md5";
import axios from 'axios'
export default {
  name: "login",
  data() {
    return {
      ruleForm: {
        username: "",
        pass: ""
      },
      loginTip: "",
      btnjump: "",
      flagdisabled:false
    };
  },
  created: function() {
    let that = this;
    document.onkeypress = function(e) {
      var keycode = document.all ? event.keyCode : e.which;
      if (keycode == 13) {
        that.loginsubmit();
        return false;
      }
    };
  },
  methods: {
    loginsubmit: function() {
      let _this = this;
    
      console.log("test");
      if (_this.ruleForm.username == "") {
        _this.loginTip = "请填写用户账号";
        _this.btnaction();
        return false;
      }
      if (_this.ruleForm.pass == "") {
        _this.loginTip = "请填写登录密码";
        _this.btnaction();
        return false;
      }
      
      this.flagdisabled = true
      // 用户名或密码不正确
      let data = new FormData();
      data.set("username", _this.ruleForm.username);
      data.set("password", md5(_this.ruleForm.pass));
      _this._API.login({
           userName: _this.ruleForm.username,
       
          password: md5(_this.ruleForm.pass)
        }).then(res => {
         this.flagdisabled = false
          let data = res.data;
          this.$message({
            type: "success",
            message: res.data.msg
          });
          window.sessionStorage.setItem("usrObj", JSON.stringify(data.data));
          _this.$router.push({ path: "/index" });
        })
        .catch(err => {
          console.log(err); 
          this.flagdisabled = false

        }); 
    //  let dataObj = {
    //    userName:'admin',
    //    password:'123456'
    //  }

    //   axios.post(`${axios.defaults.baseURL}/user/login`,dataObj)
    //   .then(res => {
    //     console.log(res);
    //   })
       
       
    },
    btnaction() {
      let _this = this;
      _this.btnjump = "jump";
      setTimeout(function() {
        _this.btnjump = "";
      }, 1000);
    }
  }
};
</script>

<style scoped lang="scss">
.login-content {
  width: 100%;
  height: 100%;
  position: fixed;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 0;
  overflow-y: auto;
  background-color: rgba(242, 242, 242, 1);
  background-image: url(../../assets/images/bg_12345.jpg);
  background-position: center bottom;
  background-repeat: no-repeat;
  background-attachment: scroll;
  background-size: 100% 100%;
  .footer {
    position: absolute;
    bottom: 20px;
    left: 50%;
    width: 1200px;
    height: 100px;
    transform: translate(-50%, 0);
    -webkit-transform: translate(-50%, 0);
    -ms-transform: translate(-50%, 0);
    img {
      border-width: 0px;
      position: absolute;
      left: 0px;
      top: 0px;
      width: 1201px;
      height: 101px;
    }
    p {
      font-size: 12px;
      color: #cccccc;
      line-height: 24px;
      border-width: 0px;
      word-wrap: break-word;
      text-align: center;
    }
  }
  .login-ban {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 500px;
    height: 580px;
    transform: translate(-50%, -50%);
    -webkit-transform: translate(-50%, -50%);
    -ms-transform: translate(-50%, -50%);
    display: flex;
    flex-direction: column;
    align-items: center;
    img {
      border-width: 0px;
      position: absolute;
      left: -10px;
      top: -10px;
      width: 521px;
      height: 601px;
    }
    .login-icon /deep/ {
      margin-top: 40px;
      .image-slot {
        width: 120px;
        height: 120px;
        background-image: url(../../assets/images/logo_12345.png);
        background-position: center bottom;
        background-repeat: no-repeat;
      }
    }
    .text {
      width: 380px;
      height: 75px;
      color: #999;
      line-height: 42px;
      text-align: center;
      z-index: 1;
      p:nth-of-type(1) {
        font-size: 32px;
        font-weight: 800;
        margin: 0;
      }
      p:nth-of-type(2) {
        font-size: 18px;
        margin: 0;
      }
    }
    .loginform {
      margin-top: 50px;
      width: 380px;
      .mine-loginput /deep/ {
        margin-bottom: 20px;
        .el-input__inner {
          height: 50px;
          line-height: 50px;
          padding: 0 40px;
        }
        .el-input__inner:hover {
          border-color: #0079fe;
        }
        .el-input__prefix {
          width: 36px;
          display: flex;
          justify-content: center;
          align-items: center;
          font-size: 24px;
        }
        .el-input__suffix .el-input__clear {
          line-height: 50px;
          font-size: 24px;
        }
        .el-input__icon {
          margin-left: 10px;
        }
      }
    }
    .pass >>> .el-input__inner {
      padding-right: 70px;
    }
    .mine-submit {
      margin-bottom: 10px;
      position: relative;
      width: 100%;
      height: 50px;
      line-height: 50px;
      padding: 0;
      font-size: 18px;
    }
    .login-tip >>> .el-alert--info.is-light {
      height: 40px;
      line-height: 40px;
      background: #999999;
      color: #ffffff;
    }
    .jump {
      position: relative;
      animation: action 1s linear;
    }
    @keyframes action {
      0% {
        top: 0px;
      }
      10% {
        top: -10px;
      }
      20% {
        top: 0px;
      }
      30% {
        top: 10px;
      }
      40% {
        top: 0px;
      }
      50% {
        top: -8px;
      }
      60% {
        top: 0px;
      }
      70% {
        top: 8px;
      }
      80% {
        top: 0px;
      }
      90% {
        top: -5px;
      }
      100% {
        top: 0px;
      }
    }
  }
}
</style>
